package com.yc.star.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yc.star.entity.Tag;
import com.yc.star.mapper.TagMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("tag")
public class TagDo {

    @Resource
    TagMapper tagMapper;

    @RequestMapping("getTags")
    public List<Tag> getTags(){
        LambdaQueryWrapper<Tag> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Tag::getIsparent,"1");
        List<Tag> tags = tagMapper.selectList(lqw);
        for (Tag tag :tags){
            LambdaQueryWrapper<Tag> lqw2 = new LambdaQueryWrapper<>();
            lqw2.eq(Tag::getParentid,tag.getId());
            List<Tag> ziTags = tagMapper.selectList(lqw2);
//            System.out.println("---------"+ziTags);
            tag.setTags(ziTags);
        }
        return tags;
    }

}
